import React from "react";
import "../css/InputBox.css";
import eventEmitter from '../event';

class InputBox extends React.Component{
  constructor(props){
    super(props)

  }

  render(){
    return(
      <div className="input_container">
        <input type="text" ref="input"/>
        <button onClick={()=>{
          console.log(this.refs.input);
          let value = this.refs.input.value;

          if(value.length === 0){
            alert("输入内容不能为空!")
            return;
          }
          var date = new Date();
          var dateStr = `${date.getFullYear()}年${date.getMonth()+1}月${date.getHours()}时${date.getMinutes()}分`
          var message ={
            content:value,
            date:dateStr
          }

          //将要传递数据的组件发布自定义事件
          eventEmitter.emit("sendMessageTooBoard",message)

        }}>提交</button>
      </div>
    );
  }
}

export default InputBox;